package com.huffman.smart_picture.api.download;

import com.huffman.smart_picture.api.download.pexels.PexelsImageApi;
import com.huffman.smart_picture.api.download.unsplash.UnsplashImageApi;
import com.huffman.smart_picture.common.exception.BusinessException;
import com.huffman.smart_picture.common.exception.ErrorEnum;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author DengLin
 * @title 图片下载工厂
 * @date 2025/3/30
 */
@Component
public class DownloadImageFactory {
    private final Map<Integer, ObtainImage> obtainImageMap = new HashMap<>();

    public DownloadImageFactory(PexelsImageApi pexelsImageApi, UnsplashImageApi unsplashImageApi) {
        this.obtainImageMap.put(1, pexelsImageApi);
        this.obtainImageMap.put(2, unsplashImageApi);
    }

    /**
     * 获取单例bean
     * @param source
     * @return
     */
    public ObtainImage getObtainImage(Integer source) {
        if (!obtainImageMap.keySet().contains(source)) {
            throw new BusinessException(ErrorEnum.PARAM_CHECK_MISTAKE, "图片源参数错误");
        }

        return obtainImageMap.get(source);
    }
}
